package demo.dubb;

import demo.dubbo.api.TimeApi;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;

import java.io.IOException;

/**
 * 生产者要素:
 * 1 application
 * 2 protocol
 * 3 registry
 * 4 serviceConfig
 */
public class Provider {
    public static void main(String[] args) throws IOException {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("test_server");

        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(-1);

        RegistryConfig registryConfig = new RegistryConfig(RegistryConfig.NO_AVAILABLE);

        ServiceConfig serviceConfig = new ServiceConfig();
        serviceConfig.setApplication(applicationConfig);
        serviceConfig.setRegistry(registryConfig);
        serviceConfig.setProtocol(protocolConfig);
        serviceConfig.setInterface(TimeApi.class);
        serviceConfig.setRef(new TimeApiImpl());

        serviceConfig.export();

        System.out.println("服务启动");

        System.in.read();
    }
}
